package day12;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author oldliu
 * @since 1.0
 */
public class ObjectServer {
    public static void main(String[] args) {
        try {
            ServerSocket st=new ServerSocket(8888);
            while (true){
                final Socket s=st.accept();
                new Thread(){
                    @Override
                    public void run() {
                        try {
                            ObjectInputStream oin=new ObjectInputStream(s.getInputStream());
                            ObjectOutputStream oout=new ObjectOutputStream(s.getOutputStream());
                            oout.writeObject("sss");
                            Object o = oin.readObject();
                            System.out.println(o);
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            try {
                                s.close();
                            } catch (Exception e) {
                               // e.printStackTrace();
                            }
                        }

                    }
                }.start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
